package Bridge;

// 实现部分：颜色接口及其具体实现
interface Color {
    void applyColor();
}

class Red implements Color {
    @Override
    public void applyColor() {
        System.out.println("应用红色");
    }
}

class Green implements Color {
    @Override
    public void applyColor() {
        System.out.println("应用绿色");
    }
}

class Blue implements Color {
    @Override
    public void applyColor() {
        System.out.println("应用蓝色");
    }
}

// 抽象部分：毛笔抽象类及其派生类
abstract class Brush {
    protected Color color;

    public void setColor(Color color) {
        this.color = color;
    }

    public abstract void draw();
}

class LargeBrush extends Brush {
    @Override
    public void draw() {
        System.out.print("大号毛笔绘图 - ");
        color.applyColor();
    }
}

class MediumBrush extends Brush {
    @Override
    public void draw() {
        System.out.print("中号毛笔绘图 - ");
        color.applyColor();
    }
}

class SmallBrush extends Brush {
    @Override
    public void draw() {
        System.out.print("小号毛笔绘图 - ");
        color.applyColor();
    }
}

// 客户端使用示例
public class BridgePattern {
    public static void main(String[] args) {
        // 创建颜色实现
        Color red = new Red();
        Color green = new Green();
        Color blue = new Blue();

        // 创建不同大小的毛笔并设置颜色
        Brush largeBrush = new LargeBrush();
        largeBrush.setColor(red);
        largeBrush.draw();

        Brush mediumBrush = new MediumBrush();
        mediumBrush.setColor(green);
        mediumBrush.draw();

        Brush smallBrush = new SmallBrush();
        smallBrush.setColor(blue);
        smallBrush.draw();

        // 动态更换颜色
        smallBrush.setColor(red);
        smallBrush.draw();
    }
}
